package com.loveprogrammer.eternity.skill.support.skills;

import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.skill.support.states.DazeState;
import com.loveprogrammer.eternity.skill.support.states.StrengthState;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @version 1.0.0
 * @description: 战吼
 * @author: eric
 * @date: 2022-08-11 16:49
 **/
public class SkillShout extends AbstractSkill {

    public SkillShout(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    public boolean check(Character character) {
        return true;
    }

    @Override
    public int opportunityPassive() {
        // 主动技能
        return 0;
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每三级升一级
        if (characterLevel % 3 == 0) {
            return true;
        }
        return false;
    }

    /***
     * 发动技能
     **/
    @Override
    public Tuple<String, List<Character>> skillLaunch(Character character,
                                                      List<? extends Character> attack,
                                                      List<? extends Character> defences) {
        Tuple<String, List<Character>> result = new Tuple<>();

        List<Character> characters = new ArrayList<>();

        // 增加力量 持续10s钟，同时增加一个状态
        int power = getHarm(character);
        StringBuilder builder = new StringBuilder();
        builder.append(character.getName()).append("(").append(character.getCurrentHp()).append("/")
                .append(character.getHpMax()).append(")").append(" 使用技能[")
                .append(getName()).append(" ").append(getLevel()).append("级】增加了自身力量 ").append(power).append("点,持续持续10s");

        // 战吼
        StrengthState strengthState = new StrengthState(character, defences, power);
        character.acquireState(strengthState,10);
        character.setStrength(character.getStrength() + power);
        setTimeTask(strengthState, 10);

        // 几率眩晕
        for (Character defence : defences) {
            if(new Random().nextInt(100) < 30){
                DazeState dazeState = new DazeState(defence, defences, 3000);
                // 眩晕就是等到下次攻击前等待一定时间
                boolean state = defence.acquireState(dazeState, 99);
                // 施展成功 3秒钟
                if (state) {
                    builder.append(defence.getName()).append("进入眩晕状态(3s);\n");
                } else {
                    builder.append(defence.getName()).append("眩晕无效;\n");
                }
            }
        }

        result.setValue(characters);
        result.setKey(builder.toString());
        return result;
    }

    @Override
    protected int computeHarm(Character character) {
        return (int) (character.getTechnique() * 0.5 + getLevel() * 80);
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 0;
    }
}
